﻿// Copyright (C) 2014  Patrick Maher

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;

namespace Paragon.Geometry
{
    public class Vec3f
    {
        public float X { get; set; }
        public float Y { get; set; }
        public float Z { get; set; }

        public Vec3f()
        {
        
        }

        public Vec3f(float x, float y, float z)
        {
            X = x;
            Y = y;
            Z = z;
        }

        public Vec3f Normalize()
        {
            float magnitude = GetMagnitude();

            X = X / magnitude;
            Y = Y / magnitude;
            Z = Z / magnitude;
            
            return this;
        }

        public float GetMagnitude()
        {
            return Convert.ToSingle(System.Math.Sqrt(X * X + Y * Y + Z * Z));
        }

        public Vec3 Clamp()
        {
            return new Vec3(Convert.ToInt32(X), Convert.ToInt32(Y), Convert.ToInt32(Z));
        }

        public static Vec3f operator + (Vec3f v1, Vec3f v2)
        {
            return new Vec3f(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z);
        }

        public static Vec3f operator - (Vec3f v1, Vec3f v2)
        {
            return new Vec3f(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);
        }

        public static Vec3f operator *(Vec3f v1, float scalar)
        {
            return new Vec3f(v1.X * scalar, v1.Y * scalar, v1.Z * scalar);
        }
    }

    //public sealed class Vec3
    //{
    //    public int X { get; set; }
    //    public int Y { get; set; }
    //    public int Z { get; set; }

    //    public Vec3()
    //    {

    //    }
        
    //    public Vec3(int x, int y, int z)
    //    {
    //        X = x;
    //        Y = y;
    //        Z = z;
    //    }

    //    public int Encode()
    //    {
    //        return NodeAddress.VectorToZOrderCurve(X, Y, Z);
    //    }
    //}
}